#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 100005;
typedef long long ll;
int t, n, m, l, v, nums[N];
ll cnt, ans, tot[N];
double dis[N], p[N];
struct car
{
    int d, v, a;
}c[N];
vector<int> vec[N];
bool cmp(int a, int b)
{
    return vec[a].size() < vec[b].size();
}
int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> t;
    while (t --)
    {
        cin >> n >> m >> l >> v;
        cnt = 0; ans = 0;
        memset(tot, 0, sizeof(tot));
        for (int i = 1; i <= m; i ++) vec[i].clear();
        for (int i = 1; i <= n; i ++)
        {
            cin >> c[i].d >> c[i].v >> c[i].a;
            if (c[i].a != 0)
            {
                if (c[i].a > 0 && c[i].v > v)
                {
                    dis[i] = l - c[i].d + 1;
                    continue;
                }
                dis[i] = (v * v - c[i].v * c[i].v) / (c[i].a << 1);
            }
            else
            {
                if (c[i].v <= v) dis[i] = 0;
                else dis[i] = l - c[i].d + 1;
            }
        }
        /*for (int i = 1; i <= n; i ++) cout << dis[i] << ' ';
        cout << '\n';*/
        for (int i = 1; i <= m; i ++) cin >> p[i];
        sort(p + 1, p + m + 1);
        for (int i = 1; i <= n; i ++)
        {
            if (dis[i] <= 0)
            {
                //cout << i << "tiaoguo" << '\n';
                continue;
            }
            if (c[i].v > v)
            {
                int r = lower_bound(p + 1, p + m + 1, c[i].d + dis[i]) - (p), l = lower_bound(p + 1, p + m + 1, c[i].d) - (p);
                //cout << ln << ' ' << r << '\n';
                if (l == 0 || r - 1 < l) continue;
                cnt ++;
                //cout << i << ' ' << "chaosu" << '\n';
                for (int j = l; j <= r - 1; j ++)
                {
                    tot[i] ++;
                    vec[j].push_back(i);
                }
            }
            else if (c[i].v < v)
            {
                int l = upper_bound(p + 1, p + m + 1, c[i].d + dis[i]) - (p), r = m;
                //cout << l << endl;
                if (l == 0 || r - 1 < l) continue;
                cnt ++;
                //cout << i << ' ' << "chaosu" << '\n';
                for (int j = l; j <= r; j ++)
                {
                    tot[i] ++;
                    vec[j].push_back(i);
                }
            }
        }
        for (int i = 1; i <= m; i ++) nums[m] = i;
        sort(nums + 1, nums + m + 1, cmp);
        /*for (int i = 1; i <= n; i ++) cout << nums[i] << ' ';
        cout << '\n';*/
        for (int i = 1; i <= m; i ++)
        {
            bool flag = true;
            for (int j = 0; j < vec[i].size(); j ++)
            {
                if (tot[vec[i][j]] <= 1) flag = false;
            }
            if (flag)
            {
                for (int j = 0; j < vec[i].size(); j ++) tot[vec[i][j]] --;
                ans ++;
            }
        }
        cout << cnt << ' ' << ans << '\n';
    }
    return 0;
}

/*
1
10 10 20660 178
1225 798 -11
12225 255 -2
3807 520 -10
15236 618 -158
1414 873 -9
7060 644 -7
3507 834 -39
14720 390 291
11498 808 -60
14535 935 -223
2802 4059 4904 8892 11895 11978 12572 15257 15877 17328

10 8
*/

/*
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 ‐2
6 4 ‐4
2 5 8 9 15

3 3
*/
